// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   VideoFrame.java

package presenter;

import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import javax.media.Player;
import javax.swing.*;

// Referenced classes of package presenter:
//            VideoPanel

public class VideoFrame extends JFrame
    implements ActionListener, WindowListener
{

    public VideoFrame(int x, int y)
    {
        vp = new VideoPanel(x, y);
    }

    public void updateBackground()
    {
        if(vp.getVideo() != null && vp.getVideo().getWidth() > 0 && vp.getVideo().getHeight() > 0)
        {
            BufferedImage bi = new BufferedImage(vp.getVideo().getWidth(), vp.getVideo().getHeight(), 1);
            java.awt.Graphics gr = bi.getGraphics();
            vp.getVideo().paintAll(gr);
            background = bi;
        }
    }

    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource() == time && vp.getPlayer() != null && vp.getPlayer().getState() == 600)
            updateBackground();
    }

    public Image getFrame()
    {
        return background;
    }

    public void loadVideo(String video)
    {
        panel = new JPanel(new BorderLayout());
        vp.loadVideo(video);
        panel.add(vp, "Center");
        panel.add(vp.getVideoControls(), "South");
        setContentPane(panel);
        setDefaultCloseOperation(2);
        pack();
        addWindowListener(this);
        setVisible(true);
        time = new Timer(40, this);
        time.start();
    }

    public void setSize(int x, int y)
    {
        vp.setSize(x, y);
        pack();
    }

    public static void main(String args[])
    {
        (new VideoFrame(800, 600)).loadVideo("../ImaginationLand2.avi");
    }

    public void windowOpened(WindowEvent windowevent)
    {
    }

    public void windowClosing(WindowEvent e)
    {
        vp.getPlayer().stop();
        vp.getPlayer().close();
    }

    public void windowClosed(WindowEvent windowevent)
    {
    }

    public void windowIconified(WindowEvent windowevent)
    {
    }

    public void windowDeiconified(WindowEvent windowevent)
    {
    }

    public void windowActivated(WindowEvent windowevent)
    {
    }

    public void windowDeactivated(WindowEvent windowevent)
    {
    }

    JPanel panel;
    VideoPanel vp;
    Image background;
    Timer time;
}
